<script setup lang="ts">
//获取当前的环境 
const env = import.meta.env;

//获取当前的环境变量
const envMode = env.MODE;
const envVITE_MODE = env.VITE_MODE;
const envURL = env.VITE_API_URL;

// 获取所有环境变量
const allEnvVars = Object.entries(env).map(([key, value]) => ({
  key,
  value: typeof value === 'object' ? JSON.stringify(value) : value
}));
</script>

<template>
  <!-- <main class="container" v-if="envMode==='development'"> -->
  <main class="container" v-if="envMode==='development'">
    <h1 class="page-title">环境信息</h1>
    
    <div class="env-info">
      <div class="info-card">
        <h2 class="section-title">主要环境变量</h2>
        <div class="main-vars">
          <div><span class="label">当前环境:</span> <span class="value">{{ envMode }}</span></div>
          <div><span class="label">环境模式:</span> <span class="value">{{ envVITE_MODE }}</span></div>
          <div><span class="label">API URL:</span> <span class="value">{{ envURL }}</span></div>
        </div>
      </div>

      <div class="info-card">
        <h2 class="section-title">所有环境变量</h2>
        <div class="table-wrapper">
          <table>
            <thead>
              <tr>
                <th>变量名</th>
                <th>值</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="item in allEnvVars" :key="item.key">
                <td>{{ item.key }}</td>
                <td>{{ item.value }}</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </main>
</template>

<style scoped>
.container {
  margin: 0 auto;
  padding: 0.5rem;
  overflow: hidden;
}

.page-title {
  color: #2c3e50;
  text-align: center;
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

.env-info {
  display: grid;
  gap: 2rem;
}

.info-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  padding: .5rem;
}

.section-title {
  color: #42b883;
  margin-bottom: 1rem;
  font-size: 1.2rem;
}

.main-vars {
  display: flex;
  justify-content: space-between;
}

.main-vars div {
  padding: 0.8rem;
  border-bottom: 1px solid #eee;
}

.label {
  color: #666;
  font-weight: 600;
}

.value {
  color: #42b883;
  font-weight: 500;
}
table-wrapper {
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.8rem;
}

th, td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

th {
  background-color: #f8f9fa;
  color: #2c3e50;
  font-weight: 600;
}

tr:hover {
  background-color: #f8f9fa;
}
</style>
